/*请求url*/
var urlData = require("../../../../../data/url.js");

var theArr = {
  list: [{
    code: 0,
    classId: 1,
    courseName: "111",
    teacherName: "xxxx",
    zhang: "../../../../../image/作业.jpg"
  },
  {
    code: 2,
    classId: 3,
    courseName: "222",
    teacherName: "yyy",
    zhang: "../../../../../image/hhh.jpg"
  }]
};



Page({
  data: {
    newarray: theArr.list,
    userId:1,
    userRole:6,
    yemian: "teacher",
    onloadUrl: urlData.urlList.organManage.organHomework.list.url,
    // onloadUrlPost: urlData.urlList.teachingManage.leaveManageSelecestudentPost.url
  },
  tiaoye: function (e) {
    console.log(e.currentTarget)
    wx.setStorage({//将当前课程id写入本地数据缓存
      key: "organHomeworkListConf",
      data: {
       classId: e.currentTarget.dataset.classid
      }
    });
    wx.navigateTo({//跳转至详情页
      url: '../organ-homework-teacherMore/organ-homework-teacherMore'
      
    })
  },
  
  /**
  * 生命周期函数--监听页面加载
  */
  onLoad: function (options) {
    // wx.getStorage({
    //   key: "loginConf",
    //   success: function (res) {
    //     console.log(res.data)
    //     that.setData({
    //       userId: res.data
    //     });
    //   }
    // });

  

     var that = this;
    wx.getStorage({
      key : 'loginConf',
      success : function(res){
        console.log(res);
        that.setData({
          userId: res.data.userId
        
        });
          wx.request({
            url: that.data.onloadUrl,//??
            method: "get",
            data: {//?
              user_id: that.data.userId,
              role: that.data.userRole
            },
            header: {
              'content-type': 'application/x-www-form-urlencoded'
            },
            success: function (res) {
              if (res.data.code == 0) {
                that.listData( res);
              }
            },
            fail: function (res) {
              console.log('刷list数据失败');
            }
          })
      }
      });
  },

  /*刷新数据*/
  listData: function ( res) {
    this.setData({//?
      newarray: res.data.list,//,
    });
  },


  /*
  两次发送课程id
*/
  // sendCourseId: function (e) {
  //   wx.request({//发送当前课程id，请求detail页的课程数据
  //     url: 'http://192.168.1.110:8000/communityDynamic/detailcourse/', //仅为示例，并非真实的接口地址
  //     data: {
  //       course_id: this.data.courseId
  //     },
  //     header: { 'content-type': 'application/json' },
  //     success: function (res) {
  //       if (code == 0) {
  //         console.log(res.data)
  //       }
  //     }
  //   });
  //   wx.request({//发送当前课程id，请求detail页的list数据
  //     url: 'http://192.168.1.110:8000/upload/', //仅为示例，并非真实的接口地址
  //     data: {
  //       course_id: this.data.courseId
  //     },
  //     header: { 'content-type': 'application/json' },
  //     success: function (res) {
  //       if (code == 0) {
  //         console.log(res.data)
  //       }
  //     }
  //   });
  // },
})
